package prastise;

import java.util.LinkedList;
import java.util.Queue;

public class MyCircularQueue {

    private int[] queue;
    private int len;

    private int head;
    private int tail;


    public MyCircularQueue(int k) {
        this.queue = new int[k + 1];
        this.len = k + 1;
    }
    
    public boolean enQueue(int value) {
        if(isFull()) {
            return false;
        }
        queue[tail] = value;
        tail = (tail + 1) % len;
        return true;
    }
    
    public boolean deQueue() {
        if(isEmpty()) {
            return false;
        }
        head = (head + 1) % len;
        return true;
    }
    
    public int Front() {
        if(isEmpty()) {
            return -1;
        }
        return queue[head];
    }
    
    public int Rear() {
        if(isEmpty()) {
            return -1;
        }
        return queue[((tail - 1) + len) % len];
    }
    
    public boolean isEmpty() {
        return head == tail;
    }
    
    public boolean isFull() {
        return (tail + 1) % len == head;
    }
}
